package org.springleaf.utils;

import java.text.DateFormat;
import java.text.SimpleDateFormat;

import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.util.StringUtils;

/**
 * 自定义的Date转换
 * @author leaf
 *
 */
public class MyCustomDateEditor extends CustomDateEditor{

	public MyCustomDateEditor(DateFormat dateFormat, boolean allowEmpty) {
		super(dateFormat, allowEmpty);
	}
	
	public MyCustomDateEditor(boolean allowEmpty) {
		super(new SimpleDateFormat("yyyy-MM-dd HH:mm:sss"),allowEmpty);
	}
	
	public void setAsText(String text) throws IllegalArgumentException {
		if(StringUtils.hasText(text) && text.length() < 11){
			text += " 00:00:00";
		}
		super.setAsText(text);
	}
}
